
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="utils.DataBaseUtil" %>
<%@ page import="save.data.PageBean" %>
<%@ page import="save.data.blogContentBean" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>博客列表页</title>
    <link rel="stylesheet" href="resources/css/bootstrap-admin.css">
    <link rel="stylesheet" href="resources/css/bootstrap.min.css">
    <link rel="stylesheet" href="resources/css/common.css">
    <link rel="stylesheet" href="resources/css/blog_list.css">


  </head>
  <body class="bg">
  <!-- 导航栏 -->
  <div class="nav d-flex">
    <img src="resources/image/log.png" alt="">
    <span class="title">我的博客系统</span>
    <!-- 使用 span 把左右两侧的元素给撑开 -->
    <span class="spacer"></span>
    <a href="index">主页</a>
    <a href="edit.jsp">写博客</a>
    <a href="quit">注销</a>
  </div>
  <!-- 版心 -->
  <div class="container">
    <!-- 左侧区域，显示用户信息 -->
    <div class="container-left">
      <!-- 用户详情 -->
      <div class="card">
        <!-- 用户的头像 -->
        <img src="resources/image/head.jpg" alt="">
        <!-- 用户名 -->
        <h3>${loginBean.username}</h3>
        <!-- 文章分类 -->
        <div class="counter">
          <span><a href="PersonalCenter.jsp" >个人中心</a></span>
        </div>

      </div>
    </div>
    <!-- 右侧区域，显示博客列表 -->
    <div class="container-right">
      <!-- 每个 blog 代表一篇博客 -->
      <%

//        Connection con =null;
//        Statement sql=null;
//        ResultSet rs=null;
//        String title;
//        String blogContent;
//        String createTime;
//        String publisher;
//        int bolgId;
//        try{
//
//
//        con = DataBaseUtil.getConnection();//获得连接池。
//        sql=con.createStatement();
//
//        String SQL =
//                "select publisher,title,createTime,content ,blogId from blog_content ";
//        rs=sql.executeQuery(SQL);//查blog_content表。
//        while (rs.next()) {
//          title= rs.getString("title");
//          blogContent=rs.getString("content");
//          createTime=rs.getString("createTime");
//          publisher=rs.getString("publisher");
//          bolgId=rs.getInt("blogId");
//          out.print("<div class= blog>");
//          out.print("<div class= title>"+title+"</div>");
//          out.print("<div class= date>发表日期："+createTime+"，发表人:"+publisher+"</div>");
//          out.print("<div class= text-ellipsis >"+ blogContent+"</div>");
//          out.print("<a href=detail?bolgId="+bolgId+" class=detail>查看全文&gt;&gt;</a>");
//          out.print("</div>");
//        }
//        }
//        catch (Exception e){
//          System.out.println("e = " + e);
//        }
//        finally{
//          DataBaseUtil.close(rs,sql,con,null);
//        }


               PageBean pageBean = (PageBean) request.getAttribute("pageBean");

            List<blogContentBean> datas = pageBean.getDatas();
            for (blogContentBean blog: datas) {
                   out.print("<div class= blog>");
          out.print("<div class= title>"+blog.getTitle()+"</div>");
          out.print("<div class= date>发表日期："+blog.getCreateTime()+"，发表人:"+blog.getPublisher()+"</div>");
          out.print("<div class= text-ellipsis >"+ blog.getBlogContent()+"</div>");
          out.print("<a href=detail?bolgId="+blog.getBlogId()+" class=detail>查看全文&gt;&gt;</a>");
          out.print("</div>");
            }



      %>
      <nav aria-label="Page navigation mt-3">
        <ul class="pagination justify-content-center">
          <%
            if (pageBean.getCurrentPage()==1){
              out.print("   <li class=\"page-item disabled\">");
              out.print(" <a class=\"page-link\" href=\"javascript:void(0)\" aria-label=\"Previous\">\n" +
                      "                                <span aria-hidden=\"true\">&laquo;</span>\n" +
                      "                            </a>");
              out.print(" </li>");}
            else if (pageBean.getCurrentPage()!=1) {

              out.print("   <li class=\"page-item\">");
              out.print("   <a class=\"page-link\" href=\"index?page="+(pageBean.getCurrentPage()-1)+"\" aria-label=\"Previous\">\n" +
                      "                                <span aria-hidden=\"true\">&laquo;</span>\n" +
                      "                            </a>");
              out.print(" </li>");
            }

          %>

          <li class="page-item"><a class="page-link" href="index?page=1" >首页</a></li>

          <%
            if (pageBean.getCurrentPage()== pageBean.getTotalPage()){
              out.print("   <li class=\"page-item disabled\">");

              out.print(" <a class=\"page-link\" href=\"javascript:void(0)\" aria-label=\"Previous\">\n" +
                      "                                <span aria-hidden=\"true\">&raquo;</span>\n" +
                      "                            </a>");
              out.print(" </li>");
            }
            else if (pageBean.getCurrentPage()!= pageBean.getTotalPage()) {
              out.print("   <li class=\"page-item\">");
              out.print("   <a class=\"page-link\" href=\"index?page="+(pageBean.getCurrentPage()+1)+"\" aria-label=\"Previous\">\n" +
                      "                                <span aria-hidden=\"true\">&raquo;</span>\n" +
                      "                            </a>");
              out.print(" </li>");
            }
          %>


        </ul>
      </nav>
  </body>
</html>
